package DP;

/**
 * https://www.lintcode.com/problem/bomb-enemy/description
 */
public class BombEnemy {

    public int maxKilledEnemies(char[][] grid) {
        // write your code here
        int rows = grid.length;
        if(rows == 0){
            return 0;
        }
        int columns = grid[0].length;
        if(columns == 0){
            return 0;
        }

        int[][] dp = new int[rows][columns];

        int max=0;
        for(int i=0; i<rows; i++){
            for(int j=0; j < columns; j++){
                int tnum = 0;
                if(grid[i][j] == '0'){
                    //先循环所有i，看多少E，再循环J，看多少E
                    for(int ti = i-1; ti >= 0; ti--){
                        if(grid[ti][j] != 'W' ){
                            if(grid[ti][j] == 'E')
                                tnum ++;
                        }else{
                            break;
                        }
                    }
                    for(int ti = i+1; ti < rows; ti++){
                        if(grid[ti][j] != 'W' ){
                            if(grid[ti][j] == 'E')
                                tnum ++;
                        }else{
                            break;
                        }
                    }

                    for(int ti = j-1; ti >= 0; ti--){
                        if(grid[i][ti] != 'W' ){
                            if(grid[i][ti] == 'E')
                                tnum ++;
                        }else{
                            break;
                        }
                    }
                    for(int ti = j+1; ti < columns; ti++){
                        if(grid[i][ti] != 'W' ){
                            if(grid[i][ti] == 'E')
                                tnum ++;
                        }else{
                            break;
                        }
                    }

                    max = Math.max(max, tnum);
                }
            }
        }

        return max;
    }



    public static void main(String[] args){
        int[] n = new int[]{-1,1,1,1};

    }


}
